#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 3;
ll c[maxn], a[maxn], b[maxn];
bool vis[maxn];
ll n, m;
int main() {
    freopen("pack.in", "r", stdin);
    freopen("pack.out", "w", stdout);
    cin >> n >> m;
    for (ll i = 1; i <= n; i++) {
        cin >> a[i] >> b[i];
    }
    for (ll i = 1; i <= m; i++) {
        ll ans = 0;
        cin >> c[i];
        memset(vis, 0, sizeof(vis));
        while (c[i]) {
            ll k = 0;
            for (ll j = 1; j <= n; j++) {
                if (!vis[j] and a[k] < a[j] and a[j] <= c[i]) 
                    k = j;
            }
            c[i] -= a[k];
            ans += b[k];
            vis[k] = 1;
            if (k == 0) break;
        }
        cout << ans << '\n';
    }
}
